package org.xx.armory.spring5.jpa;

import javax.persistence.AttributeConverter;

public class BooleanAttributeConverter
        implements AttributeConverter<Boolean, Integer> {

    @Override
    public Integer convertToDatabaseColumn(
            Boolean value
    ) {
        return value != null ? value ? 1 : 0 : null;
    }

    @Override
    public Boolean convertToEntityAttribute(
            Integer value
    ) {
        return value != null ? value != 0 : null;
    }
}
